% writes a file with the tree nodes.
% the numbers are C++ compatible : all lists start at 0 and not 1!!!
function writeTreeToFile(DecisionTree, DataSet, filename)
    fid = fopen(filename,'w');
    
    % print number of features and of tree nodes
    fprintf(fid,'%d %d\n',DataSet.numFeatures, length(DecisionTree));
    
    probas = zeros(length(DecisionTree));
    for node=1:length(DecisionTree)
        if (DecisionTree(node).totalCount==0)
           probas(node) = 0.5;
        else
            probas(node) = DecisionTree(node).positiveCount/DecisionTree(node).totalCount;
        end
    end
    
    % print out tree nodes
    for i = 1:length(DecisionTree)
        fprintf(fid, '%d %d %f %d %d %f\n',i-1,DecisionTree(i).featureNum-1, ...
            DecisionTree(i).threshold, ...
            DecisionTree(i).leftChild-1, ...
            DecisionTree(i).rightChild-1, ...
            probas(i));
    end 
    fclose(fid);
end